using AutoMapper;
using ChikovMF.Application.Common.Mappings;
using ChikovMF.Entities;

namespace ChikovMF.Application.Features.Projects.Shared;

public class ProjectModel : IMapWith<Project>
{
    public string Name { get; set; } = null!;
    public string Description { get; set; } = null!;
    public string Content { get; set; } = null!;
    public ICollection<ProjectTagModel>? Tags { get; set; }
    public ICollection<ProjectLinkModel>? Links { get; set; }

    public class ProjectTagModel : IMapWith<ProjectTag>
    {
        public int Order { get; set; }
        public Guid TagId { get; set; }

        public void Mapping(Profile profile)
        {
            profile.CreateMap<ProjectTag, ProjectTagModel>();
        }
    }

    public class ProjectLinkModel : IMapWith<Link>
    {
        public string Name { get; set; } = null!;
        public Uri Url { get; set; } = null!;

        public void Mapping(Profile profile)
        {
            profile.CreateMap<Link, ProjectLinkModel>();
        }
    }

    public void Mapping(Profile profile)
    {
        profile.CreateMap<Project, ProjectModel>()
            .ForMember(project => project.Tags,
                opt => opt.MapFrom(model => model.TagLinks))
            .ForMember(project => project.Links,
                opt => opt.MapFrom(model => model.Links));
    }
}